package com.delu.controller;

import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.CarBrand;
import com.delu.mapper.CarBrandsMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("carBrand")
@Api("汽车品牌")
public class CarBrandController {
    @Resource
    private CarBrandsMapper carBrandsMapper;

    @GetMapping
    @ApiOperation("汽车品牌查询")
    @ApiImplicitParam(name = "brandId",value = "汽车品牌ID",required = true,paramType = "query")
    public Result selectCarBrand(@RequestParam("brandId")Integer brandId){
        System.out.println("汽车品牌信息" + brandId);
        List<CarBrand> carBrandList = carBrandsMapper.selectCarBrand(brandId);
        return Result.response(ResultEnum.SUCCESS).setData(carBrandList);
    }

    @PostMapping
    @ApiOperation("汽车品牌增加")
    @ApiImplicitParam(name = "CarBrand",value = "汽车品牌实体类",required = true,paramType = "body")
    public Result insertCarBrand(@RequestBody CarBrand carBrand){
        Integer i = carBrandsMapper.insert(carBrand);
        System.out.println("汽车品牌信息" + carBrand);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @PutMapping
    @ApiOperation("汽车品牌修改")
    @ApiImplicitParam(name = "CarBrand",value = "汽车品牌实体类",required = true,paramType = "body")
    public Result updateCarBrand(@RequestBody CarBrand carBrand){
        Integer i = carBrandsMapper.updateById(carBrand);
        System.out.println("汽车品牌信息" + carBrand);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @DeleteMapping
    @ApiOperation("汽车品牌删除")
    @ApiImplicitParam(name = "brandId",value = "汽车品牌ID",required = true,paramType = "query")
    public Result deleteCarBrand(@RequestParam("brandId")Integer brandId){
        System.out.println("汽车品牌信息" + brandId);
        Integer i = carBrandsMapper.deleteById(brandId);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

}
